import { ipcMain } from 'electron'
import MockApi from '../api/mock.api'
import { IpcMockKeys } from '../../../common/enums/ipc.mock.enum'
export function registerMockIpc() {
  MockApi.initRequestInterceptor() // 初始化拦截器
  // 获取所有规则
  ipcMain.handle(IpcMockKeys.GET_MOCK_RULES, () => MockApi.getMockRules())

  // 添加新规则
  ipcMain.handle(IpcMockKeys.ADD_MOCK_RULES, (_, rule) => {
    // 生成唯一ID
    return MockApi.addMockRules(rule)
  })

  // 更新规则
  ipcMain.handle(IpcMockKeys.UPDATA_MOCK_RULES, (_, updatedRule) => {
    return MockApi.updateMockRules(updatedRule)
  })

  // 删除规则
  ipcMain.handle(IpcMockKeys.DELETE_MOCK_RULES, (_, id) => {
    return MockApi.deleteMockRules(id)
  })

  // 切换Mock开关
  ipcMain.handle(IpcMockKeys.TOGGLE_MOCK_ENABlED, (_, enabled) => {
    return MockApi.toggleMockEnabled(enabled)
  })

  // 获取Mock状态
  ipcMain.handle(IpcMockKeys.GET_MOCK_ENABlED, () => MockApi.getMockEnabled())
}
